package game.farming.model;

import game.farming.ui.Player;

import java.util.HashMap;

import org.apache.myfaces.trinidad.component.core.layout.CorePanelBox;

public abstract class Square extends CorePanelBox {
	private String message;
	
	public Square(String message) {
		setBackground("transparent");
		setContentStyle("background: #FFFF99;" + getSize());
		setInlineStyle("background: #FFFF99; margin: 0; padding: 0;" + getBorders());
		setPartialTriggers(new String[]{"dice","restartGame"});
		this.message = message;
	}
	
	public String getBorders() {
		String borders = "";
		borders += "border-top: solid black 2px;";
		borders += "border-bottom: solid black 2px;";
		borders += "border-left: solid black 1px;";
		borders += "border-right: solid black 1px;";
		return borders;
	}
	
	public String getSize() {
		return "width: 68px; height: 75px;";
	}
	
	public String getMessage() {
		return message;
	}
	
	public void setMessage(String message) {
		this.message = message;
	}
	
	public abstract void performAction(Player p, Table t);
	
	public static Square SQ_0 = new Square("CHRISTMAS VACATION. Collect $1000. Collect $5000 as you pass.") {
		public void performAction(Player p, Table t) {
			p.addCash(1000);
		}
		
		public String getSize() {
			return "width: 75px; height: 75px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 2px;";
			borders += "border-bottom: solid black 2px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 1px;";
			return borders;
		}
	};
	public static Square SQ_1 = new Square("Pay 10% on Bank notes on hand.") {
		public void performAction(Player p, Table t) {
			p.addCash((int) -0.10 * p.getLoan());
		}
	};
	public static Square SQ_2 = new Square("Hibernate. Draw O.T.B.") {
		public void performAction(Player p, Table t) {
			p.addOtb(t.drawOtb());
		}
	};
	public static Square SQ_3 = new Square("Bitter Cold Spell. Pay $500 if you own cows.") {
		public void performAction(Player p, Table t) {
			if (p.hasProduct(Product.COWS)) {
				p.addCash(-500);
			}
		}
	};
	public static Square SQ_4 = new Square("Beautiful Days. Double all your Hay harvests this year.") {
		public void performAction(Player p, Table t) {
			HashMap<Product, Double> yields = p.getYields();
			yields.put(Product.HAY, yields.get(Product.HAY) * 2);
			p.setYields(yields);
		}
	};
	public static Square SQ_5 = new Square("Warm snap, you're in the field 2 weeks early. Collect $2,000.") {
		public void performAction(Player p, Table t) {
			p.addCash(2000);
		}
	};
	public static Square SQ_6 = new Square("Stuck in a muddy corral. Draw Farmer's Fate.") {
		public void performAction(Player p, Table t) {
			//t.drawFf();
		}
	};
	public static Square SQ_7 = new Square("Ground thaws. Start plowing early. Go directly to Spring Planting.") {
		public void performAction(Player p, Table t) {
			p.moveTo(14);
			SQ_14.performAction(p, t);
		}
	};
	public static Square SQ_8 = new Square("Rainy day. Draw O.T.B.") {
		public void performAction(Player p, Table t) {
			p.addOtb(t.drawOtb());
		}
	};
	public static Square SQ_9 = new Square("Becomes Obvious your wheat has winter killed. Pay $2,000 to replant.") {
		public void performAction(Player p, Table t) {
			p.addCash(-2000);
		}
	};
	public static Square SQ_10 = new Square("Start plowing late. Pay $500.") {
		public void performAction(Player p, Table t) {
			p.addCash(-500);
		}
	};
	public static Square SQ_11 = new Square("Hurt your back. Go back to second week of January.") {
		public void performAction(Player p, Table t) {
			p.moveTo(2);
			SQ_2.performAction(p, t);
		}
	};
	public static Square SQ_12 = new Square("Frost forces you to heat fruit. Pay $2,000 if you own fruit.") {
		public void performAction(Player p, Table t) {
			if (p.hasProduct(Product.FRUIT)) {
				p.addCash(-2000);
			}
		}
	};
	public static Square SQ_13 = new Square("Done plowing. Take a day off. Draw O.T.B.") {
		public void performAction(Player p, Table t) {
			p.addOtb(t.drawOtb());
		}
	};
	public static Square SQ_14 = new Square("SPRING PLANTING Plant corn on time. Double your corn yield this year.") {
		public void performAction(Player p, Table t) {
			HashMap<Product, Double> yields = p.getYields();
			yields.put(Product.GRAIN, yields.get(Product.GRAIN) * 2);
			p.setYields(yields);
		}
		
		public String getSize() {
			return "width: 75px; height: 75px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 2px;";
			borders += "border-bottom: solid black 2px;";
			borders += "border-left: solid black 1px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_15 = new Square("More rain. Field work shut down. Pay $500") {
		public void performAction(Player p, Table t) {
			p.addCash(-500);
		}
		
		public String getSize() {
			return "width: 75px; height: 52px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 0px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_16 = new Square("Equipment breakdown. Pay $1,000.") {
		public void performAction(Player p, Table t) {
			p.addCash(-1000);
		}
		
		public String getSize() {
			return "width: 75px; height: 53px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_17 = new Square("The whole valley is green. Collect $500.") {
		public void performAction(Player p, Table t) {
			p.addCash(500);
		}
		
		public String getSize() {
			return "width: 75px; height: 53px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_18 = new Square("Windstorm makes you replant corn. Pay $500.") {
		public void performAction(Player p, Table t) {
			p.addCash(-500);
		}
		
		public String getSize() {
			return "width: 75px; height: 53px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_19 = new Square("Cut your hay just right. Collect $1000 bonus.") {
		public void performAction(Player p, Table t) {
			p.addCash(1000);
			p.harvestProduct(Product.HAY, 1.0);
		}
		
		public String getSize() {
			return "width: 75px; height: 53px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_20 = new Square("Memorial Day weekend. Draw O.T.B.") {
		public void performAction(Player p, Table t) {
			p.addOtb(t.drawOtb());
			p.harvestProduct(Product.HAY, 1.0);
		}
		
		public String getSize() {
			return "width: 75px; height: 53px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_21 = new Square("Rain storm ruins unbaled hay. Cut your harvest cheque in half.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.HAY, 0.5);
		}
		
		public String getSize() {
			return "width: 75px; height: 53px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_22 = new Square("Good growing weather. Collect $500 bonus.") {
		public void performAction(Player p, Table t) {
			p.addCash(500);
			p.harvestProduct(Product.HAY, 1.0);
		}
		
		public String getSize() {
			return "width: 75px; height: 53px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_23 = new Square("Rain splits your cherries. Cut your harvest cheque in half.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.FRUIT, 0.5);
		}
		
		public String getSize() {
			return "width: 75px; height: 53px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_24 = new Square("Dust storm. Draw Farmer's Fate.") {
		public void performAction(Player p, Table t) {
			//t.drawFf();
			p.harvestProduct(Product.FRUIT, 1.0);
		}
		
		public String getSize() {
			return "width: 75px; height: 52px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 0px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_25 = new Square("INDEPENDENCE DAY") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.FRUIT, 1.0);
		}
		
		public String getSize() {
			return "width: 75px; height: 75px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 2px;";
			borders += "border-bottom: solid black 2px;";
			borders += "border-left: solid black 1px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_26 = new Square("Good weather for your second cutting of hay. Double hay harvest cheque.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.HAY, 2.0);
		}
		
		public String getSize() {
			return "width: 92px; height: 75px;";
		}
	};
	public static Square SQ_27 = new Square("Hot! Wish you were in the mountains. Draw O.T.B.") {
		public void performAction(Player p, Table t) {
			p.addOtb(t.drawOtb());
			p.harvestProduct(Product.HAY, 1.0);
		}
		
		public String getSize() {
			return "width: 92px; height: 75px;";
		}
	};
	public static Square SQ_28 = new Square("It's a cooker! 114 degrees in the shade. Wipe your brow and go to Harvest Moon after getting hay cheque.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.HAY, 1.0);
			p.moveTo(36);
			SQ_36.performAction(p, t);
		}
		
		public String getSize() {
			return "width: 92px; height: 75px;";
		}
	};
	public static Square SQ_29 = new Square("85 degrees, wheat heads filling out beautifully. Add $50 per acre to your harvest cheque.") {
		public void performAction(Player p, Table t) {
			p.addCash(50 * p.getProductCount(Product.GRAIN));
			p.harvestProduct(Product.GRAIN, 1.0);
		}
		
		public String getSize() {
			return "width: 92px; height: 75px;";
		}
	};
	public static Square SQ_30 = new Square("You're right on time and farming like a pro. Go to the fourth week of February. Collect your years wage of $5,000.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.GRAIN, 1.0);
			p.moveTo(6);
			p.yearInit();
			SQ_6.performAction(p, t);
		}
		
		public String getSize() {
			return "width: 92px; height: 75px;";
		}
	};
	public static Square SQ_31 = new Square("Storm clouds brewing. Collect $1,000 if you own a harvestor.") {
		public void performAction(Player p, Table t) {
			if (p.hasProduct(Product.HARVESTOR)) {
				p.addCash(1000);
				p.harvestProduct(Product.GRAIN, 1.0);
			}
		}
		
		public String getSize() {
			return "width: 92px; height: 75px;";
		}
	};
	public static Square SQ_32 = new Square("Finish wheat harvest with no break downs. Collect $500.") {
		public void performAction(Player p, Table t) {
			p.addCash(500);
			p.harvestProduct(Product.GRAIN, 1.0);
		}
		
		public String getSize() {
			return "width: 92px; height: 75px;";
		}
	};
	public static Square SQ_33 = new Square("Rain sprouts unharvested wheat. Cut price $50 per acre on harvest cheque.") {
		public void performAction(Player p, Table t) {
			p.addCash(-50 * p.getProductCount(Product.GRAIN));
			p.harvestProduct(Product.GRAIN, 1.0);
		}
		
		public String getSize() {
			return "width: 92px; height: 75px;";
		}
	};
	public static Square SQ_34 = new Square("Tractor owners: bale hay, then go to third week of November. Collect your $1,000 there, then harvest your fruit.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.HAY, 1.0);
			if (p.hasProduct(Product.TRACTOR)) {
				p.moveTo(45);
				SQ_45.performAction(p, t);
			}
		}
		
		public String getSize() {
			return "width: 92px; height: 75px;";
		}
	};
	public static Square SQ_35 = new Square("Sunny skies at the County Fair. Draw O.T.B.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.HAY, 1.0);
			p.addOtb(t.drawOtb());
		}
		
		public String getSize() {
			return "width: 92px; height: 75px;";
		}
	};
	public static Square SQ_36 = new Square("HARVEST MOON smiles on you. Collect $500.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.COWS, 1.0);
			p.addCash(500);
		}
		
		public String getSize() {
			return "width: 75px; height: 75px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 2px;";
			borders += "border-bottom: solid black 2px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 1px;";
			return borders;
		}
	};
	public static Square SQ_37 = new Square("Market collapses. Cut your livestock cheque in half.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.COWS, 0.5);
		}
		
		public String getSize() {
			return "width: 75px; height: 42px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 0px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_38 = new Square("Codling moths damage apples. Pay $2,000 if you own fruit.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.COWS, 1.0);
			if (p.hasProduct(Product.FRUIT)) {
				p.addCash(-2000);
			}
		}
		
		public String getSize() {
			return "width: 75px; height: 42px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_39 = new Square("Indian summer. Collect $500.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.COWS, 1.0);
			p.addCash(500);
		}
		
		public String getSize() {
			return "width: 75px; height: 42px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_40 = new Square("Good Pheasant Hunting. Draw Farmer's Fate.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.HAY, 1.0);
			//t.drawFf();
		}
		
		public String getSize() {
			return "width: 75px; height: 42px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_41 = new Square("Park your baler for the winter. Draw O.T.B.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.HAY, 1.0);
			p.addOtb(t.drawOtb());
		}
		
		public String getSize() {
			return "width: 75px; height: 42px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_42 = new Square("Annual deer hunt. Draw Farmer's Fate.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.FRUIT, 1.0);
			//t.drawFf();
		}
		
		public String getSize() {
			return "width: 75px; height: 42px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_43 = new Square("Irrigation season over. Draw O.T.B.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.FRUIT, 1.0);
			p.addOtb(t.drawOtb());
		}
		
		public String getSize() {
			return "width: 75px; height: 42px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_44 = new Square("Good weather, harvest winding up. Collect $500.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.FRUIT, 1.0);
			p.addCash(500);
		}
		
		public String getSize() {
			return "width: 75px; height: 42px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_45 = new Square("Good weather holding. Collect $1,000.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.FRUIT, 1.0);
			p.addCash(1000);
		}
		
		public String getSize() {
			return "width: 75px; height: 42px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_46 = new Square("Early freeze kills fruit buds. Pay $1,000 if you own fruit.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.GRAIN, 1.0);
			if (p.hasProduct(Product.FRUIT)) {
				p.addCash(-1000);
			}
		}
		
		public String getSize() {
			return "width: 75px; height: 42px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_47 = new Square("Cold and dry, perfect corn harvesting. Collect $500.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.GRAIN, 1.0);
			p.addCash(500);
		}
		
		public String getSize() {
			return "width: 75px; height: 42px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 1px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
	public static Square SQ_48 = new Square("First Snow. Draw Farmer's Fate.") {
		public void performAction(Player p, Table t) {
			p.harvestProduct(Product.GRAIN, 1.0);
			//t.drawFf();
		}
		
		public String getSize() {
			return "width: 75px; height: 42px;";
		}
		
		public String getBorders() {
			String borders = "";
			borders += "border-top: solid black 0px;";
			borders += "border-bottom: solid black 1px;";
			borders += "border-left: solid black 2px;";
			borders += "border-right: solid black 2px;";
			return borders;
		}
	};
}
